import { defineStore } from "pinia";
import { store } from "@/store";
import { getList, update, add, deleted ,get ,list} from "@/api/recruiting/index";
import { ListResult, Result,getListResult } from "@/api/recruiting/index";


export const listStore = defineStore({
  id: "pure-listStore",
  actions: {
    
    async getList(req: object) {
      return new Promise<ListResult>((resolve, reject) => {
        getList(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async update(req: object) {
      return new Promise<Result>((resolve, reject) => {
        update(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async add(req: object) {
      return new Promise<Result>((resolve, reject) => {
        add(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async delete(req: object) {
      return new Promise<Result>((resolve, reject) => {
        deleted(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async get(req: object) {
      return new Promise<Result>((resolve, reject) => {
        get(req)
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    async getlist(req: object) {
        return new Promise<getListResult>((resolve, reject) => {
            list(req)
            .then(data => {
              if (data) {
                resolve(data);
              }
            })
            .catch(error => {
              reject(error);
            });
        });
      }
  }
});

export function useListStoreStoreHook() {
  return listStore(store);
}
